package vip.xiaonuo.bi.modular.dataset.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.bi.modular.dataset.param.FolderAddprama;
import vip.xiaonuo.bi.modular.dataset.param.FolderUpdateprama;
import vip.xiaonuo.bi.modular.dataset.service.DatasetFolderService;
import vip.xiaonuo.bi.modular.dataset.service.DatasetService;
import vip.xiaonuo.common.pojo.CommonResult;

@Api(tags = "数据集-文件文件夹")
@ApiSupport(author = "SNOWY_TEAM", order = 1)
@RestController
@Validated
public class FolderController {

    @Autowired
    DatasetFolderService datasetFolderService;

    @Autowired
    DatasetService datasetService;


    /**
     * 获取-文件夹树形结构列表
     * @return
     */
    @ApiOperation("数据集文件文件列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyWord", required = false, value = "关键词模糊搜索", paramType = "form"),
    })
    @GetMapping(value = "/bi/dataset/folderList")
    public CommonResult folderList(String keyWord){
        return CommonResult.data(datasetFolderService.folderlist(keyWord));
    }


    /**
     * 创建文件夹
     * @return
     */
    @ApiOperation("创建文件夹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", required = true, value = "文件夹名称", paramType = "form"),
            @ApiImplicitParam(name = "pid", required = true, value = "父集文件夹", paramType = "form")
    })
    @PostMapping(value = "/bi/dataset/careteFolder")
    public CommonResult careteFolder(@RequestBody FolderAddprama folderAddprama){
        datasetFolderService.careteFolder(folderAddprama.getName(),folderAddprama.getPid());
        return CommonResult.ok();
    }

    /**
     * 修改分组
     * @return
     */
    @ApiOperation("修改文件夹-整个文件夹为单位")
    @PostMapping(value = "/bi/dataset/update")
    public CommonResult update(@RequestBody FolderUpdateprama folderUpdateprama) {
        datasetFolderService.updateByFolderId(folderUpdateprama.getId(),folderUpdateprama.getName(),folderUpdateprama.getPid());
        return CommonResult.ok();
    }


    /**
     * 修改分组-多个文件夹移动过去
     * @return
     */
    @ApiOperation("修改文件夹-单个文件为单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", required = true, value = "数据集id==》id,id,id...", paramType = "form"),
            @ApiImplicitParam(name = "groupId", required = true, value = "分组字段", paramType = "form")
    })
    @PostMapping(value = "/bi/dataset/updateData")
    public CommonResult updateData(String ids,String folderId) {
        datasetFolderService.updateBatchByFolderId(ids,folderId);
        return CommonResult.ok();
    }

    /**
     * 删除分组
     * @return
     */
    @ApiOperation("删除文件夹(也删除数据集及里面文件夹)")
    @PostMapping(value = "/bi/dataset/delete")
    public CommonResult delete(String id) {
        datasetFolderService.deleteFolder(id);
      return   CommonResult.ok();
    }

}
